#include <stdio.h>
#include "graph.h" //请勿删除，否则检查不通过

bool insert_vertex(ListGraph *G, VertexType v){
    if(~locate_vertex(G, v) || G -> vexnum >= MAX_VERTEX_NUM) return false;
    VNode *rt = &(G -> vertex[G -> vexnum++]);
    rt -> data = v;
    rt -> firstarc = NULL;
    return true;
}

bool edge_exist(ListGraph *G, VertexType u, VertexType v) {
    ArcNode *edge = G -> vertex[u].firstarc;
    while(edge) {
        if(edge -> adjvex == v) return true;
        edge = edge -> nextarc;
    }
    return false;
}

bool insert_arc(ListGraph *G, VertexType v, VertexType w){
    v = locate_vertex(G, v); w = locate_vertex(G, w);
    if(v == -1 || w == -1 || edge_exist(G, v, w)) return false;
    ArcNode *arc = malloc(sizeof(ArcNode));
    arc -> adjvex = w;
    arc -> nextarc = G -> vertex[v].firstarc;
    G -> vertex[v].firstarc = arc;
    ++G -> arcnum;
    return true;
}
